import 'dart:convert';
import 'dart:io';
import 'dart:typed_data';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart';
// import 'package:flutter_app/config/config.dart';
// import 'package:flutter_app/services/api.dart';
// import 'package:flutter_app/widgets/button_widget.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:flutter_native_image/flutter_native_image.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
// import 'package:multi_image_picker/multi_image_picker.dart';
// import 'package:flutter_native_image/flutter_native_image.dart';
// import 'package:image_picker/image_picker.dart';
import 'package:get/get.dart' hide MultipartFile hide FormData;
import 'package:image_picker/image_picker.dart';
import 'package:multi_image_picker/multi_image_picker.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';
import 'package:yp/Xwidgets/button_widget.dart';
import 'package:yp/config/config.dart';
import 'package:yp/services/api.dart';
import 'logic.dart';
import 'state.dart';
import 'package:dio/dio.dart';



class MaterialCreatePage extends StatefulWidget {
  MaterialCreatePage({Key key}) : super(key: key);

  @override

  _MaterialCreatePage createState() {
    return _MaterialCreatePage();
  }
}

class _MaterialCreatePage extends State<MaterialCreatePage> {
  final MaterialCreateLogic logic = Get.put(MaterialCreateLogic());
  final MaterialCreateState state = Get.find<MaterialCreateLogic>().state;

  List<Asset> images = [];
  List newImg = [];
  Future<void> loadAssets(index) async {
    if(images == null){
      images = List<Asset>();
    }
    if(index==2){
      var imagesList = [];
      try{
        imagesList = await MultiImagePicker.pickImages(
          maxImages: 1,
          enableCamera: false,
          cupertinoOptions: CupertinoOptions(takePhotoIcon: "chat"),
          materialOptions: MaterialOptions(
            actionBarColor: "#FCCD00",
            actionBarTitle: "选择图片",
            allViewTitle: "所有图片",
            useDetailsView: false,
            selectCircleStrokeColor: "#000000",
          ),
        );
        if(imagesList.length != 0){
          images = imagesList;
          setState(() {});
          Navigator.of(context).pop();
        }
      } on Exception catch(e){
        Navigator.of(context).pop();
      }
      if(imagesList.length == 0) return;
      for (Asset asset in images) {
        ByteData byteData = await asset.getByteData();
        List<int> imageData = byteData.buffer.asUint8List();
        MultipartFile multipartFile = MultipartFile.fromBytes(
          imageData,
          filename: asset.name,
        );
        print('FormDataFormDataFormDataFormDataFormData');
           print(FormData);
        Api.upImage(
          FormData.fromMap({
            "file": multipartFile,
          }),
        ).listen((event) {
          if(event["code"] == 0){
            state.fileList.add(event["result"][0]["url"]);
            newImg.add(event["result"][0]["url"]);
            logic.update();
          }
        });
      }
    }else{
      try {
        final ImagePicker _picker = ImagePicker();
        var img = await _picker.pickImage(source: ImageSource.camera);
        var _image;
        var data;
        var imageData;
        if (Platform.isAndroid) {
          _image = File(img.path).path;
          var compressedFile = await FlutterNativeImage.compressImage(_image,
            quality: 10,);
          imageData = await compressedFile.readAsBytes();
        } else {
          _image = File(img.path).path;
          var compressedFile = await FlutterNativeImage.compressImage(_image,
            quality: 10,);
          data = await rootBundle.load(compressedFile.path);
          imageData = data.buffer.asUint8List();
        }
        Navigator.of(Get.context).pop();
        EasyLoading.show();
        MultipartFile multipartFile = MultipartFile.fromBytes(
          imageData,
          filename: 'a.jpg',
        );
        Api.upImage(
          FormData.fromMap({
            "file": multipartFile,
          }),
        ).listen((event) {
          if (event["code"] == 0) {
            state.fileList.add(event["result"][0]["url"]);
            newImg.add(event["result"][0]["url"]);
            logic.update();
            EasyLoading.dismiss();
          } else {
            EasyLoading.dismiss();
          }
        });
      } on Exception catch (e) {
        Navigator.of(Get.context).pop();
      }
    }

  }

  List<Widget> imageListFun(List images){
    Widget addimg = Container(
      child: GetBuilder<MaterialCreateLogic>(
        builder: (logic) {
          return Container(
            child: GestureDetector(
              onTap: () {
                selectImage(context);
              },
              child: Container(
                color: Color(0xfff4f4f4),
                width: 200.w,
                height: 200.w,
                child: Center(
                  child: Icon(
                    Icons.add,
                    color: Color(0xffBEBEBE),
                  ),
                ),
              ),
            ),
          );
        },
      ),
    ); // uploada
    var list2 = newImg.asMap().map((index,item) {
      Widget widget = Image.network('${item}',  width: 200,
          height: 200);
      return MapEntry(index, _createGridViewItem(widget, index));

    }).values.toList();

    List<Widget> list  = List<Widget>.from(list2);

    if(list.length < 9){
      list.add(addimg);
    }
    return list;
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          backgroundColor: Colors.white,
          brightness: Brightness.light,
          iconTheme: IconThemeData(color: Colors.black),
          title: Text(
            "发布素材",
            style: TextStyle(color: Colors.black, fontSize: 32.sp),
          ),
          centerTitle: true,
          elevation: .5,
        ),
        body:GetBuilder<MaterialCreateLogic>(
            builder: (logic) {
              return SingleChildScrollView(
                child:Column(
                  children: [
                    Container(
                      height: 280.w,
                      decoration: BoxDecoration(
                        color: Color(0xffFFFFFF),
                      ),
                      padding: EdgeInsets.symmetric(horizontal: 30.w),
                      child: TextField(
                        controller: state.controller,
                        style: TextStyle(fontSize: 28.sp),
                        maxLines: 5,
                        decoration: InputDecoration(
                          focusedBorder: InputBorder.none,
                          enabledBorder: InputBorder.none,
                          hintText: '请输入素材内容',
                          hintStyle: TextStyle(fontSize: 28.sp),
                        ),
                      ),
                    ),
                    Container(
                      height: 20.w,
                      color: Color(0xffF7F7F7),
                    ),
                    Container(
                      color: Color(0xffFFFFFF),
                      child: Column(
                        children: [
                          Container(
                            width: 750.w,
                            padding: EdgeInsets.symmetric(vertical: 25.w, horizontal: 15.w),
                            margin: EdgeInsets.only(right:50.w),
                            decoration: BoxDecoration(
                              border: Border(
                                bottom: BorderSide(
                                  color: Color(0xffeeeeee),
                                  width: 1.w,
                                ),
                              ),
                            ),
                            child: Wrap(
                              children:imageListFun(this.newImg),
                            ),
                          ),

                          //地址
                          state.selectAdrData != null ?
                          Container(
                            width: 750.w,
                            padding: EdgeInsets.symmetric(vertical: 30.w, horizontal: 30.w),
                            decoration: BoxDecoration(
                              border: Border(
                                bottom: BorderSide(
                                  color: Color(0xffeeeeee),
                                  width: 1.w,
                                ),
                              ),
                            ),
                            child:GestureDetector(
                              onTap: () {
                                selectAddress(context);
                              },
                              child: Column(
                                children: [
                                  Row(
                                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                                    crossAxisAlignment: CrossAxisAlignment.center,
                                    children: [
                                      Row(
                                        children: [
                                          Icon(
                                            Icons.location_on_outlined,
                                            color: Config.mainColor,
                                            size: 16,
                                          ),
                                          SizedBox(width: 5.w),
                                          Container(width:550.w,child: Text(
                                            state.selectAdrData["name"],
                                            style: TextStyle(
                                              fontSize: 28.sp,
                                              color: Color(0xffADADAD),
                                            ),
                                            maxLines: 1,
                                            textAlign: TextAlign.start,
                                            overflow: TextOverflow.ellipsis,
                                          ),),
                                        ],
                                      ),
                                      Row(
                                        children: [
                                          GestureDetector(
                                            onTap: () {
                                              state.selectAdrData = null;
                                              logic.update();
                                            },
                                            child:Image.asset(
                                              "assets/images/close.png",
                                              width: 30.w,
                                              height: 30.w,
                                            ),
                                          ),
                                          SizedBox(
                                            width: 5.w,
                                          ),
                                          Image.asset(
                                            "assets/images/icon-left.png",
                                            width: 30.w,
                                            height: 30.w,
                                          ),
                                        ],
                                      )
                                    ],
                                  ),
                                ],
                              ),
                            ),
                          ):
                          // Container(
                          //   width: 750.w,
                          //   padding: EdgeInsets.symmetric(vertical: 30.w, horizontal: 30.w),
                          //   decoration: BoxDecoration(
                          //     border: Border(
                          //       bottom: BorderSide(
                          //         color: Color(0xffeeeeee),
                          //         width: 1.w,
                          //       ),
                          //     ),
                          //   ),
                          //   child:GestureDetector(
                          //     onTap: () {
                          //       selectAddress(context);
                          //     },
                          //     child: Column(
                          //       children: [
                          //         Row(
                          //           mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          //           crossAxisAlignment: CrossAxisAlignment.center,
                          //           children: [
                          //             Row(
                          //               children: [
                          //                 Icon(
                          //                   Icons.location_on_outlined,
                          //                   color: Config.mainColor,
                          //                   size: 16,
                          //                 ),
                          //                 SizedBox(width: 5.w),
                          //                 Container(width:600.w,child: Text(
                          //                   "添加地址",
                          //                   style: TextStyle(
                          //                     fontSize: 28.sp,
                          //                     color: Color(0xffADADAD),
                          //                   ),
                          //                   maxLines: 1,
                          //                   textAlign: TextAlign.start,
                          //                   overflow: TextOverflow.ellipsis,
                          //                 ),),
                          //               ],
                          //             ),
                          //             Row(
                          //               children: [
                          //                 Image.asset(
                          //                   "assets/images/icon-left.png",
                          //                   width: 30.w,
                          //                   height: 30.w,
                          //                 ),
                          //               ],
                          //             )
                          //           ],
                          //         ),
                          //       ],
                          //     ),
                          //   ),
                          // ),

                          //商品
                          state.selectShopData != null ?
                          Container(
                            width: 750.w,
                            padding:
                            EdgeInsets.symmetric(vertical: 30.w, horizontal: 30.w),
                            decoration: BoxDecoration(
                              border: Border(
                                bottom: BorderSide(
                                  color: Color(0xffeeeeee),
                                  width: 1.w,
                                ),
                              ),
                            ),
                            child:InkWell(
                              onTap: () {
                                selectProduct(context);
                              },
                              child: Column(
                                children: [
                                  Row(
                                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                                    crossAxisAlignment: CrossAxisAlignment.center,
                                    children: [
                                      Row(
                                        children: [
                                          Image.asset(
                                            "assets/images/shop.png",
                                            width: 30.w,
                                            height: 30.w,
                                          ),
                                          SizedBox(width: 20.w),
                                          Container(
                                            width: 80.w,
                                            height: 80.w,
                                            child: Image.network(
                                              state.selectShopData["image_default_id"],
                                              width: 80.w,
                                              height: 80.w,
                                            ),
                                          ),
                                          SizedBox(width: 10.w),
                                          Container(width:450.w,child: Column(
                                            mainAxisAlignment: MainAxisAlignment.start,
                                            crossAxisAlignment: CrossAxisAlignment.start,
                                            children: [
                                              Text(
                                                state.selectShopData["title"],
                                                style: TextStyle(
                                                  fontSize: 28.sp,
                                                  color: Color(0xff222222),
                                                ),
                                                maxLines: 1,
                                                textAlign: TextAlign.start,
                                                overflow: TextOverflow.ellipsis,
                                              ),
                                              RichText(
                                                text: TextSpan(
                                                  children: [
                                                    TextSpan(
                                                      text: '￥',
                                                      style: TextStyle(
                                                          color: Color(0xff222222),
                                                          fontSize: 20.sp),
                                                    ),
                                                    TextSpan(
                                                      text: state.selectShopData["price"].toString(),
                                                      style: TextStyle(
                                                          color: Color(0xff222222),
                                                          fontSize: 32.sp),
                                                    ),
                                                    if(state.selectShopData["expect_price"] !=null && state.selectShopData["expect_price"] > 0)TextSpan(
                                                      text: '  折后价：',
                                                      style: TextStyle(
                                                          color: Config.mainColor,
                                                          fontSize: 24.sp),
                                                    ),
                                                    if(state.selectShopData["expect_price"] !=null &&  state.selectShopData["expect_price"] > 0)TextSpan(
                                                      text: state.selectShopData["expect_price"].toString(),
                                                      style: TextStyle(
                                                          color: Config.mainColor,
                                                          fontSize: 26.sp),
                                                    ),
                                                  ],
                                                ),
                                              ),

                                            ],
                                          ),),
                                        ],
                                      ),
                                      Row(
                                        children: [
                                          GestureDetector(
                                            onTap: () {
                                              state.selectShopData = null;
                                              logic.update();
                                            },
                                            child:Image.asset(
                                              "assets/images/close.png",
                                              width: 30.w,
                                              height: 30.w,
                                            ),
                                          ),
                                          SizedBox(
                                            width: 5.w,
                                          ),
                                          Image.asset(
                                            "assets/images/icon-left.png",
                                            width: 30.w,
                                            height: 30.w,
                                          ),
                                        ],
                                      )
                                    ],
                                  ),
                                ],
                              ),
                            ),
                          ):
                          Container(
                            width: 750.w,
                            padding:
                            EdgeInsets.symmetric(vertical: 30.w, horizontal: 30.w),
                            decoration: BoxDecoration(
                              border: Border(
                                bottom: BorderSide(
                                  color: Color(0xffeeeeee),
                                  width: 1.w,
                                ),
                              ),
                            ),
                            child: InkWell(
                              onTap: () {
                                selectProduct(context);
                              },
                              child: Row(
                                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                                crossAxisAlignment: CrossAxisAlignment.center,
                                children: [
                                  Row(
                                    children: [
                                      Image.asset(
                                        "assets/images/shop.png",
                                        width: 30.w,
                                        height: 30.w,
                                      ),
                                      SizedBox(width: 5.w),
                                      Text(
                                        "添加商品",
                                        style: TextStyle(
                                          fontSize: 28.sp,
                                          color: Color(0xffADADAD),
                                        ),
                                        textAlign: TextAlign.center,
                                      )
                                    ],
                                  ),
                                  Row(
                                    children: [
                                      Image.asset(
                                        "assets/images/icon-left.png",
                                        width: 30.w,
                                        height: 30.w,
                                      ),
                                    ],
                                  )
                                ],
                              ),
                            ),
                          ),
                          //发布按钮
                          Container(
                            height: 180.w,
                            color: Color(0xffFFFFFF),
                            padding: EdgeInsets.symmetric(horizontal: 58.w),
                            child: Row(
                              mainAxisAlignment: MainAxisAlignment.end,
                              children: [
                                GestureDetector(
                                  onTap: () async{
                                    logic.kocMaterialCreate();
                                  },
                                  child: Container(
                                    width: 170.w,
                                    height: 64.w,
                                    child: Center(
                                      child: Text(
                                        "发布",
                                        style: TextStyle(
                                          color: Colors.white,
                                          fontSize: 28.sp,
                                        ),
                                      ),
                                    ),
                                    decoration: BoxDecoration(
                                      color: Color(0xffEA5504),
                                      borderRadius: BorderRadius.all(
                                        Radius.circular(100.w),
                                      ),
                                    ),
                                  ),
                                ),
                              ],
                            ),
                          )
                        ],
                      ),
                    )
                  ],
                ),
              );
            }
        )
    );
  }

  //显示底部商品弹框的功能
  void selectProduct(BuildContext context) {
    //用于在底部打开弹框的效果
    showModalBottomSheet(
      isScrollControlled: true,
      builder: (BuildContext context) {
        //构建弹框中的内容
        return GetBuilder<MaterialCreateLogic>(
          builder: (logic) {
            return Container(
              color: Colors.white,
              height: ScreenUtil.defaultSize.height,
              child: Column(
                children: [
                  Container(
                    height: 176.w,
                    color: Color(0xffFFFFFF),
                    padding:
                    EdgeInsets.symmetric(vertical: 22.w, horizontal: 20.w),
                    child: Column(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        Flex(
                          direction: Axis.horizontal,
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          crossAxisAlignment: CrossAxisAlignment.center,
                          children: [
                            Expanded(
                              flex: 1,
                              child: GestureDetector(
                                onTap: () {
                                  Navigator.of(context).pop();
                                },
                                child: Text(
                                  "取消",
                                  style: TextStyle(
                                    color: Color(0xffADADAD),
                                    fontSize: 26.sp,
                                  ),
                                ),
                              ),
                            ),
                            Expanded(
                              flex: 1,
                              child: Center(
                                child: Text(
                                  "选择商品",
                                  style: TextStyle(
                                    color: Color(0xff222222),
                                    fontSize: 32.sp,
                                  ),
                                ),
                              ),
                            ),
                            Expanded(
                              flex: 1,
                              child: GestureDetector(
                                onTap: () {
                                  state.selectShopData = state.shopList[state.currentShopIndex];
                                  state.controller.text = state.selectShopData['title'];
                                  logic.update();
                                  Navigator.of(context).pop();
                                },
                                child: Row(
                                  mainAxisAlignment: MainAxisAlignment.end,
                                  children: [
                                    Container(
                                      child: ButtonWidget(
                                        borderRadius: 100.w,
                                        title: "完成",
                                        width: 140.w,
                                        height: 56.w,
                                        fontSize: 28.sp,
                                      ),
                                    ),
                                  ],
                                ),
                              ),
                            ),
                          ],
                        ),
                        Container(
                          decoration: BoxDecoration(
                            color: Color(0xffFFFFFF),
                          ),
                          child: Container(
                            height: 57.w,
                            width: 690.w,
                            decoration: BoxDecoration(
                              color: Color(0xfffF7F8FA),
                              borderRadius: BorderRadius.all(
                                Radius.circular(35.w),
                              ),
                            ),
                            child: Center(
                              child: TextField(
                                controller: state.controller1,
                                textAlignVertical: TextAlignVertical.center,
                                decoration: InputDecoration(
                                  isDense: true,
                                  prefixIcon: Icon(
                                    Icons.search_rounded,
                                    size: 20,
                                    color: Color(0xfffD2D2D2),
                                  ),
                                  contentPadding: EdgeInsets.all(0),
                                  prefixIconConstraints: BoxConstraints(
                                    maxWidth: 70.w,
                                    minWidth: 70.w,
                                  ),
                                  hintText: '商品搜索，输入商品关键字',
                                  hintStyle: TextStyle(
                                    fontSize: 26.sp,
                                    color: Color(0xffD2D2D2),
                                  ),
                                  border: InputBorder.none,
                                ),
                                onChanged: (value){
                                  logic.search(value);
                                },
                              ),
                            ),
                          ),
                        ),
                      ],
                    ),
                  ),
                  GetBuilder<MaterialCreateLogic>(
                    builder: (logic) {
                      return Expanded(
                        child: SmartRefresher(
                          controller: state.controller2,
                          onRefresh: logic.refreshData,
                          onLoading: logic.loadMoreData,
                          enablePullUp: true,
                          enablePullDown: true,
                          child: ListView.builder(
                            shrinkWrap: true,
                            itemBuilder: (ctx, index) {
                              return GetBuilder<MaterialCreateLogic>(
                                builder: (logic) {
                                  return GestureDetector(
                                    onTap: () {
                                      logic.onShopSelected(index);
                                    },
                                    child: buildShopListItem(index,index == state.currentShopIndex),
                                  );
                                },
                              );
                            },
                            itemCount: state.shopList.length,
                          ),
                        ),
                      );
                    },
                  ),
                ],
              ),
            );
          },
        );
      },
      context: context,
    );
  }

  //底部地址选择
  void selectAddress (BuildContext context) {
    //用于在底部打开弹框的效果
    showModalBottomSheet(
        isScrollControlled: true,
        builder: (BuildContext context) {
          //构建弹框中的内容
          return Container(
            color: Colors.white,
            height: ScreenUtil.defaultSize.height,
            child: Column(
              children: [
                Container(
                  height: 176.w,
                  color: Color(0xffFFFFFF),
                  padding: EdgeInsets.symmetric(vertical: 22.w, horizontal: 20.w),
                  child: Column(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Flex(
                        direction: Axis.horizontal,
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        crossAxisAlignment: CrossAxisAlignment.center,
                        children: [
                          Expanded(
                            flex: 1,
                            child: GestureDetector(
                              onTap: () {
                                Navigator.of(context).pop();
                              },
                              child: Text(
                                "取消",
                                style: TextStyle(
                                  color: Color(0xffADADAD),
                                  fontSize: 26.sp,
                                ),
                              ),
                            ),
                          ),
                          Expanded(
                            flex: 1,
                            child: Center(
                              child: Text(
                                "选择地址",
                                style: TextStyle(
                                  color: Color(0xff222222),
                                  fontSize: 32.sp,
                                ),
                              ),
                            ),
                          ),
                          Expanded(
                            flex: 1,
                            child: GestureDetector(
                              onTap: () {
                                state.selectAdrData = state.adrList[state.currentAdreIndex];
                                print("选中地址${state.selectAdrData}");
                                logic.update();
                                Navigator.of(context).pop();
                              },
                              child: Row(
                                mainAxisAlignment: MainAxisAlignment.end,
                                children: [
                                  Container(
                                    child: ButtonWidget(
                                      borderRadius: 100.w,
                                      title: "完成",
                                      width: 140.w,
                                      height: 56.w,
                                      fontSize: 28.sp,
                                    ),
                                  ),
                                ],
                              ),
                            ),
                          ),
                        ],
                      ),
                      Container(
                        decoration: BoxDecoration(
                          color: Color(0xffFFFFFF),
                        ),
                        child: Container(
                          height: 57.w,
                          width: 690.w,
                          decoration: BoxDecoration(
                            color: Color(0xfffF7F8FA),
                            borderRadius: BorderRadius.all(
                              Radius.circular(35.w),
                            ),
                          ),
                          child: Center(
                            child: TextField(
                              controller: state.controller1,
                              textAlignVertical: TextAlignVertical.center,
                              decoration: InputDecoration(
                                isDense: true,
                                prefixIcon: Icon(
                                  Icons.search_rounded,
                                  size: 20,
                                  color: Color(0xfffD2D2D2),
                                ),
                                contentPadding: EdgeInsets.all(0),
                                prefixIconConstraints: BoxConstraints(
                                  maxWidth: 70.w,
                                  minWidth: 70.w,
                                ),
                                hintText: '地址搜索，输入地址关键字',
                                hintStyle: TextStyle(
                                  fontSize: 26.sp,
                                  color: Color(0xffD2D2D2),
                                ),
                                border: InputBorder.none,
                              ),
                            ),
                          ),
                        ),
                      ),
                    ],
                  ),
                ),
                Expanded(
                  child: ListView.builder(
                    shrinkWrap: true,
                    itemBuilder: (ctx, index) {
                      return GestureDetector(
                        child: GetBuilder<MaterialCreateLogic>(
                          builder: (logic) {
                            return GestureDetector(
                              onTap: () {
                                logic.onAdrSelected(index);
                              },
                              child: buildAdrListItem(index,index == state.currentAdreIndex),
                            );
                          },
                        ),
                      );
                    },
                    itemCount: state.adrList.length,
                  ),
                ),
              ],
            ),
          );
        },
        context: context );
  }

  //照片选择
  void selectImage(BuildContext context) {
    //用于在底部打开弹框的效果
    showModalBottomSheet(
        builder: (BuildContext context) {
          //构建弹框中的内容
          return Container(
            height: 300.w,
            child: Column(
              children: [
                Container(
                  child: Column(
                    mainAxisAlignment: MainAxisAlignment.end,
                    children: [
                      InkWell(
                        onTap: () async{
                          loadAssets(1);
                        },
                        child: Container(
                          height: 90.w,
                          width: 750.w,
                          decoration: BoxDecoration(
                            border: Border(
                              bottom: BorderSide(
                                color: Color(0xffeeeeee),
                                width: 1.w,
                              ),
                            ),
                          ),
                          child: Center(
                            child: Text(
                              "拍摄",
                              style: TextStyle(
                                // color: Color(0xff2222),
                                color: Colors.black,
                                fontSize: 32.sp,
                              ),
                              textAlign: TextAlign.center,
                            ),
                          ),
                        ),
                      ),
                      InkWell(
                        onTap: () async{
                          loadAssets(2);
                        },
                        child: Container(
                          height: 90.w,
                          width: 750.w,
                          child: Center(
                            child: Text(
                              "从手机相册选择",
                              style: TextStyle(
                                // color: Color(0xff2222),
                                color: Colors.black,
                                fontSize: 32.sp,
                              ),
                              textAlign: TextAlign.center,
                            ),
                          ),
                        ),
                      ),
                    ],
                  ),
                ),
                Container(
                  color: Color(0xffF2F3F4),
                  height: 20.w,
                ),
                Expanded(
                  child: InkWell(
                    onTap: () {
                      Navigator.of(context).pop();
                    },
                    child: Container(
                      child: Column(
                        mainAxisAlignment: MainAxisAlignment.end,
                        children: [
                          Container(
                            height: 90.w,
                            width: 750.w,
                            child: Center(
                              child: Text(
                                "取消",
                                style: TextStyle(
                                  // color: Color(0xff2222),
                                  color: Colors.black,
                                  fontSize: 32.sp,
                                ),
                                textAlign: TextAlign.center,
                              ),
                            ),
                          ),
                        ],
                      ),
                    ),
                  ),
                )
              ],
            ),
          );
        },
        context: context);
  }

  //图片展示
  _createGridViewItem(widget, index) {
    return Container(
      height: 200.w,
      width: 200.w,
      color: Color(0xff999999),
      margin: EdgeInsets.only(right:20.w,bottom: 20.w),
      child: Stack(
        children: [
          widget,
          Positioned(
            top: 0,
            right: 0,
            child: GestureDetector(
              onTap: () {
                setState(() {
                  // images.removeAt(index);
                  newImg.removeAt(index);
                  state.fileList.remove(index);
                });
              },
              child: Icon(
                Icons.close,
                color: Colors.grey,
              ),
            ),
          )
        ],
      ),
    );
  }

  /// 商品列表
  Widget buildShopListItem(index,bool isSelected) {



    return Container(
      color: Color(0xffFFFFFF),
      padding: EdgeInsets.symmetric(horizontal: 20.w),
      child: Container(
        color: isSelected ? Config.mainColor : Colors.white,
        padding: EdgeInsets.symmetric(horizontal: 20.w, vertical: 20.w),
        child: Row(
          children: [
            state.shopList[index]["image_default_id"] == null?
            Container(
              width: 140.w,
              height: 140.w,
            ):
            Container(
              width: 140.w,
              height: 140.w,
              child:Image.network(
                state.shopList[index]["image_default_id"],
                width: 140.w,
                height: 140.w,
              ),
            ),
            SizedBox(width: 20.w),
            Expanded(
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                mainAxisAlignment: MainAxisAlignment.spaceAround,
                children: [
                  Text(
                    state.shopList[index]["title"],
                    style: TextStyle(
                      fontSize: 28.sp,
                      color: isSelected ? Colors.white : Color(0xff222222),
                    ),
                    maxLines: 1,
                    overflow: TextOverflow.ellipsis,
                  ),
                  SizedBox(height: 10.w),
                  Row(
                    children: [
                      Row(
                        children: [
                          Text(
                            state.shopList[index]["price"].toString(),
                            style: TextStyle(
                              fontSize: 32.sp,
                              color:
                              isSelected ? Colors.white : Color(0xff222222),
                              height: 1.4,
                            ),
                          ),
                        ],
                      ),
                      SizedBox(width: 24.w),
                      if(state.shopList[index]["expect_price"] !=null && state.shopList[index]["expect_price"] > 0)Text(
                        "折后价：${state.shopList[index]["expect_price"]}",
                        style: TextStyle(
                          fontSize: 24.sp,
                          color: isSelected ? Colors.white : Config.mainColor,
                          height: 1.7,
                          // decoration: TextDecoration.lineThrough,
                        ),
                      ),
                    ],
                  ),
                  SizedBox(height: 10.w),
                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Row(
                        children: [
                          Text(
                            "佣金比例：15%",
                            style: TextStyle(
                              fontSize: 24.sp,
                              color:
                              isSelected ? Colors.white : Color(0xff222222),
                              height: 1.4,
                            ),
                          ),
                          SizedBox(
                            width: 10.w,
                          ),
                          // RichText(
                          //   text: TextSpan(
                          //     children: [
                          //       TextSpan(
                          //         text: '预计赚',
                          //         style: TextStyle(
                          //           color: isSelected
                          //               ? Colors.white
                          //               : Color(0xff222222),
                          //           fontSize: 24.w,
                          //         ),
                          //       ),
                          //       TextSpan(
                          //         text: '￥989',
                          //         style: TextStyle(
                          //           color: isSelected
                          //               ? Colors.white
                          //               : Config.mainColor,
                          //           fontSize: 24.w,
                          //         ),
                          //       ),
                          //     ],
                          //   ),
                          // ),
                        ],
                      ),
                    ],
                  )
                ],
              ),
            )
          ],
        ),
      ),
    );
  }

  /// 地址列表
  Widget buildAdrListItem(index,bool isSelected) {
    return Container(
      color: Color(0xffFFFFFF),
      padding: EdgeInsets.symmetric(horizontal: 20.w),
      child: Container(
        color: isSelected ? Config.mainColor : Colors.white,
        padding: EdgeInsets.symmetric(horizontal: 20.w, vertical: 20.w),
        child: Row(
          children: [
            Expanded(
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                mainAxisAlignment: MainAxisAlignment.spaceAround,
                children: [
                  Text(
                    state.adrList[index]["name"],
                    style: TextStyle(
                      fontSize: 28.sp,
                      color: isSelected ? Colors.white : Color(0xff222222),
                    ),
                    maxLines: 1,
                    overflow: TextOverflow.ellipsis,
                  ),
                  Text(
                    state.adrList[index]["address"],
                    style: TextStyle(
                      fontSize: 22.sp,
                      color: isSelected ? Colors.white : Color(0xff222222),
                    ),
                    maxLines: 1,
                    overflow: TextOverflow.ellipsis,
                  ),
                ],
              ),
            )
          ],
        ),
      ),
    );
  }
}